CmdUtils.CreateCommand({
  name: "revuu",
  takes: {"name": noun_arb_text},
  author: { name: "Olivier Girardot", email: "ssaboum@gmail.com"},
  contributors: ["Olivier Girardot","Jonathan Winandy"],
  license: "GPL",
  description: "Look after a package on revu. v2.2",
  help: "Insert the name of the package you want to look after, it will preview the last comment added on revu (after logging in), and if you press return, it will take you to the details page of the package.",

  preview: function( pblock , person) {

    var msg = "Search for a package :";
    var baseUrl = "http://revu.ubuntuwire.com/feed.py";
    var params = {package: trim(person.text)};
    pblock.innerHTML =msg;

    jQuery.ajax({
			type: "GET",
			url: baseUrl,
			data: params,
			dataType: "xml",
			error: function() {
				pblock.innerHTML = "No package of this name was found on REVU";
			},
			success: function(data) {
                            var reg = / is not on REVU\./gi;
                            if(reg.test(data)){
                                    pblock.innerHTML = "No package of this name was found on REVU";
                            } else {
		                    var dataPro="<i>Last comment added on this package :</i><br/>";
     		                    pblock.innerHTML = dataPro+"<br/> "+jQuery("title:contains(\"Comment\")",data).eq(0).text()+ " <br/><br/> <li>" + jQuery("entry:has(title:contains(\"Comment\"))",data).find("summary").eq(0).text()+ "</li>";
		            }
                          }  
                         });
  },

  execute: function( person ) {
    var url = "http://revu.ubuntuwire.com/details.py?package={QUERY}"
    var query = trim(person.text);
    var urlString = url.replace("{QUERY}",query);
    Utils.openUrlInBrowser(urlString);
  }
})


